﻿using System;
using System.Web.Mvc;
using Web_App___AWS_ELB_Monitor.Entities;
using Web_App___AWS_ELB_Monitor.Models.EC2;

namespace Web_App___AWS_ELB_Monitor.Controllers
{
    public class EC2MonitorController : Controller
    {
        public ActionResult Instance(string instanceId)
        {
            var model = new InstanceMonitorViewModel
                            {
                                CPUChartDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             CPUUtilization, "Percent").
                                    ToGoogleChartDatedDataTableRows(),
                                NetworkINChartDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             NetworkIn, "Percent").
                                    ToGoogleChartDatedDataTableRows(),
                                NetworkOutChartDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             NetworkOut, "Percent").
                                    ToGoogleChartDatedDataTableRows(),
                                DiskReadBytesDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             DiskReadBytes, "Percent").
                                    ToGoogleChartDatedDataTableRows(),
                                DiskWriteBytesDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             DiskWriteBytes, "Percent").
                                    ToGoogleChartDatedDataTableRows(),
                                DiskReadOpsDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             DiskReadOps, "Percent").
                                    ToGoogleChartDatedDataTableRows(),
                                DiskWriteOpsDataTY2W =
                                    CloudWatchDataHelper.Get24HourPeriodEC2InstanceCount(instanceId, DateTimeOffset.Now, true,
                                                                                         AnalyticsValueType.Average,
                                                                                         CloudWatchDefaultMetricEC2.
                                                                                             DiskWriteOps, "Percent").
                                    ToGoogleChartDatedDataTableRows()
                            };
            return View("InstanceMonitor", model);
        }
    }
}